<?php
/* Class IdentityObject
 * Documentation can be found at:
* https://github.com/mozilla/openbadges/wiki/Assertions#identityobject */

class IdentityObject {
	
	/* Mandatory fields */
	private $identity;
	private $type;
	private $hashed;	
	
	/* Optional fields */
	private $salt;
	
	/* Getters & Setters */
	public function getIdentity() {
		return $this->identity;
	}
	
	public function setIdentity($identity) {
		$this->identity = $identity;
	}
	
	public function getType() {
		return $this->type;
	}
	
	public function setType($type) {
		$this->type = $type;
	}
	
	public function getHashed() {
		return $this->hashed;
	}
	
	public function setHashed($hashed) {
		$this->hashed = $hashed;
	}
	
	public function getSalt() {
		return $this->salt;
	}

	public function setSalt($salt) {
		$this->salt = $salt;
	}
	
	public function checkValidity() {
		
		if (isset($this->identity) && isset($this->type) && isset($this->hashed)) {
			
			if ($this->hashed) {
				return isset($this->salt);
			} else {
				return TRUE;
			}
		}
		
		return FALSE;
	}
	
	public function getArray() {
	
		if (!$this->checkValidity())
			return null;
	
		$array["identity"] = $this->identity;
		$array["type"] = $this->type;
		$array["hashed"] = $this->hashed;
	
		if (isset($this->salt))
			$array["salt"] = $this->salt;
	
		return $array;
	}

}
?>